﻿using System;

namespace WebAnalyser.Api
{
    public delegate void TriggerGridUpdate(string test);
    public delegate void TriggerChangesPending();

    public class Events
    {
        private Events()
        {

        }

        public event TriggerGridUpdate GridUpdateEvent;
        public event TriggerChangesPending ChangesPendingEvent;

        private static readonly Object SyncLock = new Object();

        private static volatile Events _instance;
        public static Events Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (SyncLock)
                    {
                        if (_instance == null)
                        {
                            _instance = new Events();
                        }
                    }
                }
                return _instance;
            }
        }

        public void TriggerGridUpdate(string test)
        {
            if (GridUpdateEvent != null)
            {
                GridUpdateEvent(test);
            }
        }

        public void TriggerChangesPending()
        {
            if (ChangesPendingEvent != null)
            {
                ChangesPendingEvent();
            }
        }
    }
}
